Cleaning up small shared functions

Cleaning up small shared functions and moving them to appropriate files