Added Documentation

Added some documentation and cleaned the code