fixed bugs, first working version