Added more error checking in expression code