Fixed refresh issues and cleaned code.