improved implementation of scroll