More bug fixes, need to write tests...