This might not work properly, but if someone wants to improve upon it, here it is.