Modularize the code a little.