cleaned up and optimized a little