fixed two very hard to understand bugs, pffff!