Added error handling middleware + some minor cleanup