Added more comments, Cleaned up functionality