fixed mem handling bug and new class layout nearly complete