Added functionality and did some cleanup