Updated with more tests and improved maintainability + readability 

I checked the google docs, the format seems correct.