Simplified code + some cleanup