improve code a bit