Refactored to a small lib