Refactored cost updating and moved these function to slot. Also added tests