Some tweaks for utility functions and code clean up