bug fixes, still not completely working