Further cleanup
Removed the defines where possible
Cleaned up some functions
Further separated logic out of h files
Merge branch 'development'