Small fixes regarding to memory and exceptions management