added some optimizations, cleaned up BEM code