fixed bugs, seems to be working