Changed exception handling + some small fixes.