Struggled for a long time for a stupid bug