Code refactor, added functions