Reformatted code. Included function comments as function docs (triple quotes).