Transferred some logic from the previous bp to code