updated and cleaned some code