fix and improve code