added documentation and a few additional functions, cleaned up old code