Cleaned up code, added comments.

Signed-off-by: Rohith Chandran <rohithX@gmail.com>