4/28/14 - rewrote code for easy readability and maintainence. Also added
some new functions