cleaned up and added better comments