Actually works, although code is shit