Move code execution to separate function