Finally got the proper scoping etc. working