refactored stuff a bit