Optimized and debugged a lot