Refactored code.

Refactored a lot of code to remove redundancies and extracted all
Constants to a file.
Added more detailed notes in README for easy reference.