Modified code to allow for proper slider behaviour