Fixed some serious bugs

Switched to using a method stack this fixes the using directive,
unordered functions and orphaned blocks.
Orphaned blocks now work properly.