non-correct working version. needs refactoring