Moved render sort dialog code to its own function.
Moved window resize code to its own function.
Moved tail functionality to its own function.