refactor and rebuild gem