error fix and code cleanup - new approach how to work with typescript