added documentation, cleaned up the code