added more comments, code fully annotated