Commented and tidied up CPU code