Moved variables inside of one function so that things are allocated dynamically.