refactored midnight formula to not use insane parameters.