Split rendering routine into a separate function

ISSUE=#2