the final (working) code