Fixing stack trace and other issues caused by refactor