final code-reviewed and working device code