Add more error handling and some issue fixing