Removing unused code causing fatal error