Refactoring for performance tweaks and code readability