Refactor to be more functional, with help of Auto

Auto: http://github.com/google/auto