Code is run before code before it finishes

You are on the correct forum.

You will need to provide more context though, the snippets you have provided are not sufficient. Post all relevant code.