added tons of error checking