new gem logic from cholrei/alipy