Moved duplicated code to an initialation function