rewrite. fixes bugs with deferred loading