Just some odds and ends. Removed bitwise nonsense because the compiler is smarter than me.