Modified to get rid of the annoying bug