refactored module initialization to fix data layout/casting bug