Cleaned code and added documentation