Improve code style and performance