Added more checking, minor changes