Code fixed and formatted a bit. boolean functions are bork