optimization & code cleanup