Simplified. Used ALT where appropriate.