Too many changes

Various bug fixes, still doesn't work properly yet