Fixed exception behaviour and some other bugs