Fixed code style violations and reduce complexity