Fixed up scope allocations. Handled routine code emission and function calling