refactored a lot of code...