Refctor and tidy