ref #10. Works but need to be refactor
ref #18. Works good