fix bugs, now works