[Build] Fix build errors, optimize code a bit for previous spell fixes.