Added validy checkings
Added validy checkings
Added functions