Tidied code. Added first MySQL queries.