cleaned up comments and arranged functions