reformatting and fix direction check