major cleanup& extending functionality