Cleaned up code and removed old unused functions