almost finished implementation, not working properly yet