Separated drawing code from main code