final cleaned up code