More improvements, fixes and tests