fix due to liam comments. some code refactored