Fixed bug in reward function. Cleaned some old variables, and added comments.