Change min required API to 12, modify some code