added some error handling
handled more stuff