clean up work

refactor algorithm to clean up gemfile, specifications and make implementation code more expressive