main functionality, works fine