Major performance tweaks and support for more gcodes

Also improved the documentation in some areas and removed dead code.