Added state diagram and further small fixes. Final