Error handling for all functions done