Added basic error checking.