working version without UI part