corrected logic

plus some code standards