max deviation working properly