refactored code to utilize basisjoin where necessary