completed code (dirty)

completed code (dirty)