Added a few validity checks