Fixed issues with variable scope, static functions & output HTML