Added a validate code method