speeding up likelihood calculation