bug fixes. Mostly working