included error handling and exceptions