Fixed logic for set functions so that they do not fail every single time.
Fixed setting of wrong internal variables.