Implement ANSI and refactor console