Autojoin capability

resolves #11
resolves #4
Fix memory allocation errors