added docs and changed the code to be more readable