Cleaned up and commented the code. Final.