Cleaned up functions. Added some comment.s