Added verifications and fixed bug.