Added validation stuff and created tests