cleaned code, add comments