This is not very generic. It could be much better. I wrote it for myself, maybe someone else could improve it