wokring but ugly class implementation