working version with classes