Performance tweaks and code simplifications