Ensure lastError doesn't exceed 255. 

Remove static variable in favor of return codes.