Refactored code for faster page init.