Refactored frontend module and removed duplicate code

Frontend module repeats  functions for distutils and cli interface, I tried to merge this parts of code.