Havent tried implementing this myself (and Im not saying that this is a good/recommendable solution) but: