Replaced console output to file output
Refactored some drawing code
Generalized the condition function