Fixed focus bug, cleaned up code