More error handeling added