Best practice for code optimization