updated code based on kodimon