Refactored drawing of elements & fixed a bug in rendering