Cleaned up and improved HTML parsing (still a bit messy)