Refactorings to lib to make ricochet possible