refactored bad source code