Fixed few bugs with compile source and cleaned up some code