Added basic error checking