refactor code to be closer to master, style nits