added more error checking on initialization