simplified the code to highlight the issue