working version, but without tests and etc.