better cost handling
merged version 0.4.2