cleaned up code, added speed option, fixed white-space issues