Added a little documentation and cleaned code