rebuilding a lot of functions... what a mess :(