code more or less working