Fixed numerous bugs.