Major rewrite for MoGL library