various messy code updates
bug fixes