Implemented is_space_free with better error handling.