Refactoring code in RPS branch

@gabebw @jsteiner
indentation is off