final working version complete