Fixed autoscroll problem (Also cleaned up code)