Help improve this code

Does anyone have any idea what might be the problem?