Made code tweaks for performance