First draft of service class, also fixes some small issues.