corrected prince's code