Removed a lot of repetetive code. Requires an update to CGF