Solution using standard library