move patch code to one place && retain last 3 lines when scroll to bottom