Added comments, externalized some methods.