Got something working, but probably buggy