lots of bug fixing