Cleaned code and added some comments/documentation