ENH: cleaned up code format, added comments