Fixed some issues. Added some validation