major overhaul which i'm too lazy to split into single commits :/