Cleaned up code

Added functions to keep code clean