Simplified code, it should work now