fix html issue, refactor globals, cleanup code