Simplified code. Fixed the merge.