Adding some clearer comments, cleaning up code a little