cleaned code and added notes