Optimize get_dipoles() but there may be issues
Fix for optimization