Refactor and fix support for leap