Code restructure & tidy