updated code after the competition