initial working version moved and refactored from atomojo project