cleanup & optimize code