Cleaned up some stuff and documented some functions