Fix various bugs and make it actually work