some bug fixes, but also made things messier