Derivekey fixes

Please review.