reorganized code for consistency
code style improvements