Applies some fixes to compute correct values, however, we get stack over
flows in certain cases and bad performance
Changes computation into an posteriori computation so that no stack
overflow can occur