Fix some errors and refactoring

- Make codes more Rubyish.
- Fix some errors.
- Add Test codes, test tasks and travis config.