Fixed some scope issues, fixed code markup errors